package com.chris.homecare.screens
{
	import com.chris.homecare.components.BreadcrumbComponenet;
	import com.chris.homecare.components.BulletHeadingComp;
	import com.chris.homecare.components.HeaderComponent;
	import com.chris.homecare.components.renderers.ServicesListRenderer;
	import com.chris.homecare.data.DataUtil;
	import com.chris.homecare.data.FetchRemoteData;
	import com.chris.homecare.data.Services;
	import com.chris.homecare.utils.CommonUtils;
	import com.chris.homecare.utils.ScreenNames;
	
	import feathers.controls.List;
	import feathers.controls.Screen;
	import feathers.controls.ScrollText;
	import feathers.controls.renderers.IListItemRenderer;
	import feathers.layout.VerticalLayout;
	
	import starling.display.Quad;
	import starling.events.Event;
	
	[Event(name="triggerServiceDetailScreen",type="starling.events.Event")]
	public class ServicesScreen extends Screen
	{
		public static const TRIGGER_SERVICEDETAIL_SCREEN:String = "triggerServiceDetailScreen";
		
		private var headerComp:HeaderComponent;
		private var breadcrumbComp:BreadcrumbComponenet;
		private var bulletHeadingComp:BulletHeadingComp;
		private var scrollText:ScrollText;
		private var servicesList:List;
		public function ServicesScreen()
		{
			super();
		}
		
		override protected function initialize():void
		{
			CommonUtils.previousScreen = ScreenNames.MENU_SCREEN;
			
			this.layout = new VerticalLayout();
			
			headerComp = new HeaderComponent();
			headerComp.addEventListener(Event.COMPLETE, onMenuBtnTrigger);
			addChild(headerComp);
			
			breadcrumbComp = new BreadcrumbComponenet("Info", "Our Services");
			addChild(breadcrumbComp);
			
			bulletHeadingComp = new BulletHeadingComp("Our Services");
			addChild(bulletHeadingComp);

			servicesList = new List();
			servicesList.paddingTop = 2;
			servicesList.paddingBottom = 2;
			
			servicesList.dataProvider = DataUtil.getAllServices();
			servicesList.itemRendererFactory = function ():IListItemRenderer
			{
				var renderer:ServicesListRenderer = new ServicesListRenderer();
				return renderer;
			};
			servicesList.addEventListener(Event.CHANGE, onServicesListChange);
			addChild(servicesList);
			servicesList.backgroundSkin = new Quad(10,10,0xFFFFFF);
			servicesList.backgroundDisabledSkin = new Quad(10,10,0xFFFFFF);
			
			super.initialize();
		}
		
		override protected function draw():void
		{
			servicesList.width = stage.stageWidth;
			servicesList.height = stage.stageHeight - servicesList.y - 10*CommonUtils.scaleValue;
			
			super.draw();
		}
		
		private function onServicesListChange(event:Event):void
		{
			FetchRemoteData.choosenServiceData = servicesList.selectedItem as Services;
			this.dispatchEventWith(TRIGGER_SERVICEDETAIL_SCREEN);
		}
		
		private function onMenuBtnTrigger(event:Event):void
		{
			this.dispatchEventWith(Event.COMPLETE);
		}
	}
}